package com.lx.algorithm.temp;

import java.util.Stack;

/**
 * Description:
 * Copyright:   Copyright (c)2019
 * Company:     zefu
 *
 * @author: 张李鑫
 * @version: 1.0
 * Create at:   2021-10-26 11:47:36
 * <p>
 * Modification History:
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2021-10-26     张李鑫                     1.0         1.0 Version
 */
public class ReverseStack {
    /**
     * 不使用额外空间去反转栈
     */


    public static void main(String[] args) {
        Stack<Integer> stack = new Stack<>();
        stack.push(1);
        stack.push(2);
        stack.push(3);
        stack.push(4);
        stack.push(5);
        reverse(stack);
        System.out.println(123);
    }


    public static void reverse(Stack stack){
        if (stack.isEmpty()){
            return;
        }
        int process = process(stack);
        reverse(stack);
        stack.push(process);
    }

    public static int process(Stack<Integer> stack) {
        Integer pop = stack.pop();
        if (stack.isEmpty()) {
            return pop;
        } else {
            int reverse = process(stack);
            stack.push(pop);
            return reverse;
        }
    }
}
